home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01b.txt
/
000057_icon-group-sender_Mon Mar 12 08:26:49 2001.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f2CFQkM11692
for icon-group-addresses; Mon, 12 Mar 2001 08:26:46 -0700 (MST)
Message-Id: <200103121526.f2CFQkM11692@baskerville.CS.Arizona.EDU>
From: jwormsley@debitek.com (Jeffrey A. Wormsley)
X-Newsgroups: comp.lang.apl,comp.lang.forth,comp.lang.icon,comp.lang.lisp,comp.lang.mumps,comp.lang.scheme,comp.lang.smalltalk
Subject: Re: New Scientist Puzzle
Date: Mon, 12 Mar 2001 15:03:36 -0000
User-Agent: Xnews/03.09.22
Cache-Post-Path: real.nextlec.net!unknown@102-1.du-92.mt0.cha1.dialup.nextlec.net
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)
X-Complaints-To: newsabuse@supernews.com
To: icon-group@cs.arizona.edu
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 1977
Can't help be throw a very verbose and fly right at it Delphi solution
in... Certaily isn't 5 lines like the K solution, but then I can't read
the K solution ;^).
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Function Match(I,J : Integer): Boolean;
Procedure FindMatches;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
Function TForm1.Match(I,J : Integer): Boolean;
Var S : String;
K, L : Byte;
Begin
Result := False; // Assume no match
S := IntToStr(Sqr(I)) + IntToStr(Sqr(J)); // Build string
If (S[3] <> S[6]) or (S[5] <> S[8]) then // Check the E's and N's
Exit; // Exit if not matched
S := S[1] + S[2] + S[3] + S[4] + S[5] + S[7]; // Remove dup E's and N's
For K := 1 to Length(S) - 1 Do // Scan for dups
For L := K + 1 to Length(S) Do
If S[K] = S[L] then // If dup found
Exit; // Exit
Result := True; // Good match if this far
End;
Procedure TForm1.FindMatches;
Var I, J, A, B : Byte;
Begin
For I := 34 to 89 do
Begin
A := I div 10; B := I mod 10; // Get digits
If A <> B then // Can't work if equal
Begin
J := A + (B * 10); // Transpose digits
If Match(I,J) then // Check for match
Memo1.Lines.Add( 'VIER = ' + IntToStr(Sqr(I)) +
' NEUN = ' + IntToStr(Sqr(J)) +
' (' + IntToStr(I) + ',' + IntToStr(J) + ')');
End;
End;
End;
procedure TForm1.Button1Click(Sender: TObject);
begin
FindMatches;
end;
end.
Jeff.